package com.winit.schedule.core.repository;

import java.util.List;

import com.winit.schedule.core.model.JobID;
import com.winit.schedule.core.repository.constants.TaskItemStatus;
import com.winit.schedule.core.repository.entity.TaskItemEntity;
import com.winit.schedule.core.repository.entity.TaskRunnerEntity;

public interface TaskItemRepository {

    TaskItemEntity saveTaskItem(TaskItemEntity taskEntity);

    List<TaskItemEntity> saveTaskItem(List<TaskItemEntity> taskEntitys);

    TaskItemEntity findAndFetchTaskItemByTaskId(String taskTrackerUuid, String taskId, long nextRunTime, int fetchNum);

    List<TaskItemEntity> getTaskItemByTaskId(String taskId);

    void updateTaskRunnerForTaskItem(TaskRunnerEntity runner);

    void updateTaskRunnerForTaskItem(List<TaskRunnerEntity> runners);

    void removeTaskItemByTaskId(String taskId);

    void removeTaskRunnerByTaskTrackerUuid(String taskTrackerId);

    void completeTaskItemByTaskRunnerUuid(String taskRunnerUuid, List<String> taskItemIds, TaskItemStatus status);

    public List<TaskItemEntity> findRunningTaskItemsByTaskId(String taskId);

    long findRunningTaskItemNumByTaskId(String taskId);

    /**
     * 将push失败的taskitem状态重置为INACTIVITE,
     * 
     * @param timeout
     * @return
     */
    void recoveryPushFailureTaskItem(long timeout);

    long findRunningTaskItemNumByJobId(List<String> taskIds);

    void updateNextRunTime(JobID jobId, List<String> taskIds, long nextRunTime);

    /**
     * 根据任务ID查询任务项的数量
     * 
     * @param taskId
     * @return
     */
    long queyTaskItemNumByTaskId(String taskId, long currentTime);
}
